#pragma once
#include <thread>
#include <string>
#include <map>
#include <queue>
#include <mutex>

#include "clcomcommand.h"

class CStrCommandCenter
{
public:
	void Subscribe(
		string strcmd,
		CStrCommandObserver* pob);

	void Cancel(
		string strcmd,
		CStrCommandObserver* pob);

	void Cancel(
		CStrCommandObserver* pob);

public:
    qint64 PostCommand(
        CLComCommand& command,
		bool bNeedResult);

    bool GetCommandResult(qint64 id, CLComCommand& command);

public:
	CStrCommandCenter();
	~CStrCommandCenter();

private:
	static void DispatchCommand(CStrCommandCenter* pThis);

private:
     map<qint64,
		map<string, bool>>		m_mapSubscribes;

	 map <string,
        map<qint64,
		CStrCommandObserver*>>	m_mapkeyObs;

     queue<CLComCommand*>			m_cmds;
     map<qint64, bool>		m_mapNeedResult;
     map<qint64, CLComCommand*>	m_mapResults;

	 mutex						m_lock;

	 bool						m_bRelease;

	 thread*					m_pThread;
};

